package com.ruoyi.web.wapper;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.wapper.BaseControllerWrapper;
import com.ruoyi.market.constant.SystemConstant;

import java.util.List;
import java.util.Map;

public class ChannelUnionInfoWapper extends BaseControllerWrapper {

    public ChannelUnionInfoWapper(Map<String, Object> single) {
        super(single);
    }

    public ChannelUnionInfoWapper(List<Map<String, Object>> multi) {
        super(multi);
    }

    private List<Map<String, Object>> productList;
    public ChannelUnionInfoWapper setProductList(List<Map<String, Object>> productList) {
        this.productList = productList;
        return this;
    }

    @Override
    public void wrapTheMap(Map<String, Object> map) {

        try {

            String reuslt = "";
            String unionProdIds = (String)map.get("unionProdIds");
            JSONArray jsonArraySource = JSON.parseArray(unionProdIds);
            if (ObjectUtil.isNotEmpty(jsonArraySource) && jsonArraySource.size() > 0){
                for (int index = 0; index < jsonArraySource.size(); index++){
                    String valueitem = jsonArraySource.getString(index);
                    for (Map<String, Object> itemMap: productList){
                        Long value = (Long) itemMap.get("value");
                        String name = (String) itemMap.get("name");
                        if (StringUtils.equals(String.valueOf(value), valueitem)){
                            reuslt = reuslt + name + " | ";
                        }
                    }
                }
            }
            map.put("unionProdIds", reuslt);

        }catch (Exception ex){
            ex.printStackTrace();
        }
    }
}
